package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.service.MenuService;
import com.itheima.advantagesup.vo.MenuVO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys_menu")
@RequiredArgsConstructor
public class MenuController {
    private MenuService menuService;

    @Autowired
    public MenuController(MenuService menuService) {
        this.menuService = menuService;
    }

    @GetMapping("/allData")
    public R<List<MenuVO>> allMenu() {
        List<MenuVO> Menv = menuService.allMenu();
        System.out.println(Menv);
        return R.success(Menv);
    }

    @PostMapping("/add")
    public R<?> addMenu(@RequestBody MenuVO Menu) {
        System.out.println(Menu);
        menuService.addMenu(Menu);
        return R.success();
    }

    @PostMapping("/update")
    public R<?> updateMenu(@RequestBody MenuVO Menu) {
        System.out.println(Menu);
        menuService.updateMenu(Menu);
        return R.success();
    }

    @GetMapping("/del")
    public R<?> delMenu(String id) {
        menuService.delMenu(id);
        return R.success();
    }

    @GetMapping("/rowInfo")
    public R<MenuVO> rowInfoMenu(String id) {
       MenuVO menuVOS = menuService.rowInfoMenu(id);
        return R.success(menuVOS);
    }
}
